﻿#include "meeting_video_frame.h"
#include "video_stream.h"
#include <sstream>

MeetingVideoFrameController::MeetingVideoFrameController() : delegate_(nullptr) {
  Device::Video::Listener::Add(this);
  Stream::Video::Listener::Add(this);
}

MeetingVideoFrameController::~MeetingVideoFrameController() {
  Device::Video::Listener::Remove(this);
  Stream::Video::Listener::Remove(this);
}

int MeetingVideoFrameController::SetDelegate(IMeetingVideoFrameCtrlDelegate* delegate) {
  delegate_ = delegate;
  return 0;
}

void MeetingVideoFrameController::OnAddCamera(const char* device_id, bool add) {

}

void MeetingVideoFrameController::OnCameraPreview(const char* device_id, uint8_t* data,
                                                  uint32_t data_size, uint32_t format,
                                                  uint32_t width, uint32_t height) {
  std::string id = Device::Video::GetSelectedCamera();
  if (0 != strcmp(id.c_str(), device_id)) {
    return;
  }

  if (delegate_) {
    delegate_->OnVideoFrame(MeetingVideoFrame(data_size, data, format, width, height, 0, 0, "camera"));
  }
}

void MeetingVideoFrameController::OnVideoStreamFrame(uint64_t uin, uint8_t* data,
                                                     uint32_t data_size, int32_t format,
                                                     uint32_t width, uint32_t height,
                                                     uint32_t rotate, const char* stream) {
  if (delegate_) {
    delegate_->OnVideoFrame(MeetingVideoFrame(data_size, data, format, width, height, rotate, uin, stream));
  }
}